package com.itheima.pool;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DataPool {
    //创建一个容器,保存connection连接对象
     private static List<Connection> list = Collections.synchronizedList(new ArrayList<>()) ;
    static {
        for (int i = 1; i <=10 ; i++) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "root");
                list.add(con);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public Connection getConnection(){

        return con;
    }
}
